<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace AdminsBundle\Helper;


class MyForms{

    protected  $EM;

    public function __construct($em)
    {
        $this->EM = $em;
    }

    public function getClasses($className , $nameFeildName)
    {
        $rep = $this->EM->getRepository("AdminsBundle:$className");
        $allClasses = $rep->findAll();
        $classes = array();
        foreach ($allClasses as $class) {
            $func = "get$nameFeildName";
            $classes[$class->getId()] = $class->$func();
        }
        return $classes;
    }

    public function FoodClass()
    {

        /*name*/
        $name = array(
            "label"     =>"分类名称",
            "showType"  =>"text",
            "dataType"  =>"*2-200",
            "option"    => array()
        );

        /*orders*/
        $orders = array(
            "label"     =>"显示排序",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        return array(
            "name"   => $name,
            "orders"   => $orders,
        );
    }

    public function Product()
    {
        /*Cid*/
        $category = $this->getClasses("Category","Name");
        foreach ($category as $key => $cat) {
            $rep = $this->EM->getRepository("AdminsBundle:Category");
            $class = $rep->find($key);
            if ($class->getParent() != 0 ) {
                unset($category[$key]);
            }
        }
        $temp = array("全部");
        $options["cid"]["attr"] = array(
            "onChange"   => 'mainCatClick($(this))',
        );
        $options["cid"]["other"] = array(
            "choices"   => array_merge($temp,$category),
        );
        $config["cid"] = array(
            "label"     =>"分类",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $options["cid"]
        );
//
//        $options["bool"]["other"] = array(
//            "choices"   => array("0"=>"否","1"=>"是"),
//        );
//
//        $config["isNew"] = array(
//            "label"     =>"新品推荐",
//            "showType"  =>"radio",
//            "dataType"  =>"",
//            "option"    => $options["bool"]
//        );
//
//        $config["isHot"] = array(
//            "label"     =>"热卖推荐",
//            "showType"  =>"radio",
//            "dataType"  =>"",
//            "option"    => $options["bool"]
//        );
//
//        $config["isSale"] = array(
//            "label"     =>"折扣推荐",
//            "showType"  =>"radio",
//            "dataType"  =>"",
//            "option"    => $options["bool"]
//        );
//
//        $config["isFamous"] = array(
//            "label"     =>"名品推荐",
//            "showType"  =>"radio",
//            "dataType"  =>"",
//            "option"    => $options["bool"]
//        );

        $config["no"] = array(
            "label"     =>"产品编号",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["name"] = array(
            "label"     =>"产品名称",
            "showType"  =>"text",
            "dataType"  =>"*1-50",
            "option"    => array()
        );

        $config["marketPrice"] = array(
            "label"     =>"市场价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["price"] = array(
            "label"     =>"销售价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["stockPrice"] = array(
            "label"     =>"进货价格",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["num"] = array(
            "label"     =>"现有库存",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );

//        $config["searchInfo"] = array(
//            "label"     =>"检索信息",
//            "showType"  =>"hidden",
//            "dataType"  =>"",
//            "option"    => array("attr" => array("readonly"=>"readonly"))
//        );

        return $config;
    }



    public function ProductProduce()
    {

        $config["company"] = array(
            "label"     =>"生产厂家",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["address"] = array(
            "label"     =>"生产地址",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["time"] = array(
            "label"     =>"生产日期",
            "showType"  =>"date",
            "dataType"  =>"*",
            "option"    => array()
        );

        return $config;
    }

    public function ProductShow()
    {

        $config["title"] = array(
            "label"     =>"显示标题",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["info"] = array(
            "label"     =>"产品简介",
            "showType"  =>"textarea",
            "dataType"  =>"*",
            "option"    => array(
                "attr"=>array("style"=>"width:298px;height:150px;border:1px solid #ddd;line-height:30px;")
            )
        );

        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img1"] = array(
            "label"     =>"橱窗图一",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img2"] = array(
            "label"     =>"橱窗图二",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["img3"] = array(
            "label"     =>"橱窗图三",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array()
        );

        $config["intro"] = array(
            "label"     =>"图文介绍",
            "showType"  =>"hidden",
            "dataType"  =>"",
            "option"    => array()
        );

        return $config;
    }



    public function ProductNote()
    {

        $options["bool"]["other"] = array(
            "choices"   => array("0"=>"否","1"=>"是"),
        );

        $config["isWebIndex"] = array(
            "label"     =>"首页推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["bool"]
        );

        $config["isNew"] = array(
            "label"     =>"新品推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["bool"]
        );

        $config["isHot"] = array(
            "label"     =>"热卖推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["bool"]
        );

        $config["isSale"] = array(
            "label"     =>"折扣推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["bool"]
        );

        $config["isFamous"] = array(
            "label"     =>"名品推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["bool"]
        );
        return $config;
    }

    public function ArticleClass()
    {

        /*name*/
        $name = array(
            "label"     =>"分类名称",
            "showType"  =>"text",
            "dataType"  =>"*2-200",
            "option"    => array()
        );

        /*orders*/
        $orders = array(
            "label"     =>"显示排序",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        return array(
            "name"   => $name,
            "orders"   => $orders,
        );
    }


    public function Article()
    {
        /*Cid*/
        $options["cid"]["other"] = array(
            "choices"   => $this->getClasses("ArticleClass","Name"),
        );
        $config["cid"] = array(
            "label"     =>"信息分类",
            "showType"  =>"select",
            "dataType"  =>"*",
            "option"    => $options["cid"]
        );
        /*isIndex*/
        $options["isIndex"]["other"] = array(
            "choices"   => array(0=>"否",1=>"是"),
        );
        $config["isIndex"] = array(
            "label"     =>"首页推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["isIndex"]
        );

        $config["title"] = array(
            "label"     =>"标题",
            "showType"  =>"text",
            "dataType"  =>"*5-20",
            "option"    => array()
        );
        $config["count"] = array(
            "label"     =>"点击量",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );
        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["banner"] = array(
            "label"     =>"Banner图",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["introduction"] = array(
            "label"     =>"摘要",
            "showType"  =>"textarea",
            "dataType"  =>"*5-250",
            "option"    => array("attr"=>array("style"=>"width:98%;height:150px;"))
        );
        $config["content"] = array(
            "label"     =>"正文",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );

        return $config;
    }


    public function NewsClass()
    {

        /*name*/
        $name = array(
            "label"     =>"分类名称",
            "showType"  =>"text",
            "dataType"  =>"*2-200",
            "option"    => array()
        );

        /*orders*/
        $orders = array(
            "label"     =>"显示排序",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );

        return array(
            "name"   => $name,
            "orders"   => $orders,
        );
    }

    public function News()
    {
        /*Cid*/
        $options["cid"]["other"] = array(
            "choices"   => $this->getClasses("NewsClass","Name"),
        );
        $config["cid"] = array(
            "label"     =>"信息分类",
            "showType"  =>"select",
            "dataType"  =>"*",
            "option"    => $options["cid"]
        );
        /*isIndex*/
        $options["isIndex"]["other"] = array(
            "choices"   => array(0=>"否",1=>"是"),
        );
        $config["isIndex"] = array(
            "label"     =>"首页推荐",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["isIndex"]
        );

        $config["title"] = array(
            "label"     =>"标题",
            "showType"  =>"text",
            "dataType"  =>"*5-20",
            "option"    => array()
        );
        $config["count"] = array(
            "label"     =>"点击量",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );
        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["banner"] = array(
            "label"     =>"Banner图",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["introduction"] = array(
            "label"     =>"摘要",
            "showType"  =>"textarea",
            "dataType"  =>"*5-250",
            "option"    => array("attr"=>array("style"=>"width:98%;height:150px;"))
        );
        $config["content"] = array(
            "label"     =>"正文",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );

        return $config;
    }

    public function Page()
    {
        $config["title"] = array(
            "label"     =>"标题",
            "showType"  =>"text",
            "dataType"  =>"*2-20",
            "option"    => array()
        );
        $config["count"] = array(
            "label"     =>"点击量",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );
        $config["orders"] = array(
            "label"     =>"排序",
            "showType"  =>"text",
            "dataType"  =>"n",
            "option"    => array()
        );
        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["banner"] = array(
            "label"     =>"Banner图",
            "showType"  =>"pic",
            "dataType"  =>"",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["introduction"] = array(
            "label"     =>"摘要",
            "showType"  =>"textarea",
            "dataType"  =>"*5-250",
            "option"    => array("attr"=>array("style"=>"width:98%;height:150px;"))
        );
        $config["content"] = array(
            "label"     =>"正文",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );

        return $config;
    }

    public function SiteSetting()
    {
        $config["name"] = array(
            "label"     =>"配置名",
            "showType"  =>"text",
            "dataType"  =>"*1-20",
            "option"    => array()
        );
        $config["key"] = array(
            "label"     =>"键KEY",
            "showType"  =>"text",
            "dataType"  =>"*1-30",
            "option"    => array()
        );
        $config["value"] = array(
            "label"     =>"值VALUE",
            "showType"  =>"text",
            "dataType"  =>"*1-30",
            "option"    => array()
        );
        $config["intro"] = array(
            "label"     =>"说明",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }

    public function Category()
    {
        $options["parent"]["other"] = array(
            "choices"   => $this->getClasses("Category","Name"),
        );
        $config["parent"] = array(
            "label"     =>"上级分类",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $options["parent"]
        );
        $config["name"] = array(
            "label"     =>"分类名称",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );
        $config["index"] = array(
            "label"     =>"搜索关键词",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }

    public function CategoryAttribute()
    {
        $options["cid"]["other"] = array(
            "choices"   => $this->getClasses("Category","Name"),
        );
        $config["cid"] = array(
            "label"     =>"所属分类",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $options["cid"]
        );
        $config["attrName"] = array(
            "label"     =>"属性名称",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );
        return $config;
    }

    public function CategoryAttributeValue()
    {
        $options["attrId"]["other"] = array(
            "choices"   => $this->getClasses("CategoryAttribute","attrName"),
        );
        $config["attrId"] = array(
            "label"     =>"属性名称",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $options["attrId"]
        );
        $config["attrVal"] = array(
            "label"     =>"属性值",
            "showType"  =>"text",
            "dataType"  =>"*",
            "option"    => array()
        );
        return $config;
    }



    public function Activity()
    {
        $options["status"]["other"] = array(
            "choices"   => array(0=>"结束",1=>"开始"),
        );
        $config["status"] = array(
            "label"     =>"活动状态",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["status"]
        );

        $options["type"]["other"] = array(
            "choices"   => array(1=>"品牌",2=>"礼品",3=>"专题"),
        );
        $config["type"] = array(
            "label"     =>"活动类型",
            "showType"  =>"radio",
            "dataType"  =>"",
            "option"    => $options["type"]
        );

        $config["title"] = array(
            "label"     =>"标题",
            "showType"  =>"text",
            "dataType"  =>"*5-20",
            "option"    => array()
        );
        $config["cover"] = array(
            "label"     =>"封面图片",
            "showType"  =>"pic",
            "dataType"  =>"*",
            "option"    => array("other"=>array("required"=>False))
        );
        $config["content"] = array(
            "label"     =>"活动介绍",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["orders"] = array(
            "label"     =>"显示顺序",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["conditions"] = array(
            "label"     =>"筛选条件",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array(
                "attr" => array("readonly"=>"readonly")
            )
        );

        return $config;
    }

}